//
//  TTMusicMyPageCollectionCell.m
//  TTMusic
//
//  Created by 马金晖 on 16/3/31.
//  Copyright © 2016年 cpy. All rights reserved.
//

#import "TTMusicMyPageCollectionCell.h"
#import "TTMusicMyPageSixTableViewCell.h"
#import "MyPagelistTableViewCell.h"
#import "CPYMVTableViewCell.h"
#import "CPYMVModel.h"
#import "MVUrlModel.h"
@implementation TTMusicMyPageCollectionCell

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        
        self.dataSource = [NSMutableArray arrayWithCapacity:0];
        self.countArray = [NSMutableArray arrayWithCapacity:0];
        
        
        self.title = @[@"本地歌曲", @"下载歌曲",@"最近播放",@"我喜欢",@"下载MV",@"听歌识曲"];
        
        self.pic = @[@"1",@"2",@"3",@"1-1",@"2-1",@"3-1"];
        
        self.backgroundColor = [UIColor colorWithRed:244/255.0 green:244/255.0 blue:244/255.0 alpha:1];
        self.myPageTableView = [[TTMusicBaseTableView alloc] initWithFrame:CGRectZero];
        self.myPageTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        
        self.myPageTableView.delegate = self;
        self.myPageTableView.dataSource =self;
        [self.myPageTableView registerClass:[CPYMVTableViewCell class] forCellReuseIdentifier:@"CPYMVTableViewCellIdentifier"];
        [self.myPageTableView registerClass:[MyPageSearchTableViewCell class] forCellReuseIdentifier:@"One"];
        [self.myPageTableView registerClass:[TTMusicMyPageSixTableViewCell class] forCellReuseIdentifier:@"TTMusicMyPageSixTableViewCellIdentifier"];
        
        [self.contentView addSubview:self.myPageTableView];
        
        self.dataSource = [[YHY_DataBaseTool shareDataBase]  selectCPYMVModelTable];
        
//        [self.myPageTableView reloadData];
        
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(oboserverAction) name:@"shuaxin" object:nil];
        
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(oboserverAction) name:@"shuaxin1" object:nil];
    }
    return self;
}

- (void)oboserverAction {
    [self.myPageTableView reloadData];
}

- (void)layoutSubviews {
    [super layoutSubviews];
    self.myPageTableView.frame = CGRectMake(0, 0, self.contentView.bounds.size.width, self.contentView.bounds.size.height - 64);
}

- (NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
    return 2;
}
//
//- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
////    if (section == 2) {
////        return @"最近收藏";
////    }
//    return nil;
//}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if (section == 0) {
        return 1;
    }
//    if (section == 1) {
        return 1;
//    }
//    return self.dataSource.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if (indexPath.section == 0) {
        MyPageSearchTableViewCell *searchCell = [self.myPageTableView dequeueReusableCellWithIdentifier:@"One"];
        searchCell.backgroundColor = [UIColor colorWithRed:244/255.0 green:244/255.0 blue:244/255.0 alpha:1];
        return searchCell;
    }
//    if (indexPath.section == 1) {
        TTMusicMyPageSixTableViewCell *sixCell = [self.myPageTableView dequeueReusableCellWithIdentifier:@"TTMusicMyPageSixTableViewCellIdentifier"];
       
            sixCell.title = self.title;
            sixCell.pic = self.pic;
            return sixCell;
//    }
//
//    CPYMVTableViewCell *cell = [self.myPageTableView dequeueReusableCellWithIdentifier:@"CPYMVTableViewCellIdentifier"];
//    
////    CPYMVModel *mvModel = self.dataSource[indexPath.row];
    
//    cell.shareModel = mvModel;
    
//    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if (indexPath.section == 0) {
        return 54;
    }
//    else if (indexPath.section == 1) {
        return 300;
//    }else {
//        
//        return 250;
//    }
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [self.myPageTableView deselectRowAtIndexPath:indexPath animated:YES];
    if (indexPath.section == 0) {
    
        [self.delegate push];
    }
    if (indexPath.section == 1) {
        NSLog(@"6666");
    }
    
//    if (indexPath.section == 2) {
//        
//        CPYMVModel *mvModel = self.dataSource[indexPath.row];
//        [[NSNotificationCenter defaultCenter] postNotificationName:@"playMV" object:mvModel.url];
//        
//    }
    
}

//#pragma mark - 删除tableView
//
////设置删除样式
//- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
//    return UITableViewCellEditingStyleDelete;
//}
//
////是否允许编辑
//- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
//    return YES;
//}
//
////完成编辑
//- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
//    
//    if (editingStyle == UITableViewCellEditingStyleDelete) {
//        
//        CPYMVModel *mvModel = self.dataSource[indexPath.row];
//        // 先移除数据 再删除行
//        [self.dataSource removeObjectAtIndex:indexPath.row];
//        [self.myPageTableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationMiddle];
//        [[YHY_DataBaseTool shareDataBase] deleteCPYMVModelTable:mvModel.bigPicUrl];
//        
//        [self.myPageTableView reloadData];
//        
//    }
//}




/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
